package com.example.demo.order;

import com.ebadagang.springboot.rocketmq.message.Demo01Message;
import com.example.demo.Demo01AccountMessage;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
@RocketMQMessageListener(
        topic = Demo01AccountMessage.TOPIC,
        consumerGroup = "demo01-consumer-group-" + Demo01AccountMessage.TOPIC
)
public class Demo01Consumer implements RocketMQListener<Demo01AccountMessage> {

    @Autowired
    private RedisTemplete redisTemplete;

    private Logger logger = LoggerFactory.getLogger(getClass());

    @Override
    public void onMessage(Demo01AccountMessage message) {
        //订单项目监听账户服务发送的用户信息修改的消息

        //将修改的内容维护到redis中
        ValueOperation operation=(ValueOperation<k,v>)redisTemplete.opsForValue();
        operation.set("USER"+message.getId(),message.getData());
        logger.info("[onMessage][线程编号:{} 消息内容：{}]", Thread.currentThread().getId(), message);
    }

}